package test.enba.openfeign.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import test.enba.openfeign.client.UserServiceClient;
import test.enba.openfeign.client.req.User;

@RestController
@RequestMapping("/openfeign")
public class OpenFeignController {

  @Autowired private UserServiceClient userServiceClient;

  // 根据用户 ID 获取用户信息
  @GetMapping("/{id}")
  public User getUserById(@PathVariable Long id) {
    return userServiceClient.getUserById(id);
  }

  // 获取所有用户信息
  @GetMapping
  public List<User> getAllUsers() {
    return userServiceClient.getAllUsers();
  }

  // 创建新用户
  @PostMapping
  public User createUser(@RequestBody User user) {
    return userServiceClient.createUser(user);
  }

  // 更新用户信息
  @PutMapping("/{id}")
  public User updateUser(@PathVariable Long id, @RequestBody User user) {
    return userServiceClient.updateUser(id, user);
  }

  // 删除用户
  @DeleteMapping("/{id}")
  public void deleteUser(@PathVariable Long id) {
    userServiceClient.deleteUser(id);
  }
}
